package org.bjf.springboot.web;

import java.util.List;
import javax.annotation.Resource;
import org.bjf.springboot.domain.User;
import org.bjf.springboot.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created by binjinfeng on 2017/1/19.
 */
@RestController
@RequestMapping(value = "user")
public class UserController {

  @Resource
  private UserService userService;

  @GetMapping("list")
  public List<User> list() {
    return userService.list();
  }

  @PostMapping("add")
  public String add(@Validated User user) {
    userService.add(user);
    return "success";
  }

  @GetMapping("{id}")
  public User get(@PathVariable Integer id) {
    return userService.get(id);
  }


}
